/*
 * Copyright 2021-2022 the original author(https://github.com/wj596)
 * 
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * </p>
 */
package org.jsets.noresubmit.config;

import org.jsets.fastboot.exception.BadRequestException;
import org.jsets.noresubmit.aspectj.ResubmitAspect;
import org.jsets.noresubmit.cache.TokenCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 操作日志组件配置
 *
 * @author wangjie (https://github.com/wj596)
 * @date 2021.07.10 23:56
 */
@Configuration
public class ResubmitConfig {
	
	private static final Logger log = LoggerFactory.getLogger(TokenCache.class);
	
	private static final Integer TOKEN_CACHE_EXPIRE = 5;
	private static final String RESUBMIT_TIPS = "请不要重复提交";
	
	@Bean
	public ResubmitAspect resubmitAspect() {
		TokenCache tokenCache = new TokenCache(TOKEN_CACHE_EXPIRE);
		return new ResubmitAspect(tokenCache, token->{
			throw new BadRequestException(RESUBMIT_TIPS);
		});
	}

}